package com.example.demo.Controller;

import com.example.demo.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("thymeleaf")
public class ThymeleafController {
    @GetMapping("/variable")
    public ModelAndView variable(){
        ModelAndView modelAndView = new ModelAndView("example/thymeleaf");
        String name = "gandinghui";
        Integer age = 8;
        modelAndView.addObject("name", name);
        modelAndView.addObject("age", age);
        return modelAndView;
    }
    @GetMapping("/list")
    public ModelAndView list(){
        List<Object> list = new ArrayList<>();
        list.add("北京");
        list.add("上海");
        list.add("深圳");
        ModelAndView modelAndView = new ModelAndView("example/list");
        modelAndView.addObject("list", list);
        modelAndView.addObject("list", list);
        return modelAndView;
    }
    @GetMapping("/list2")
    public ModelAndView list2(){
        List<User> list = new ArrayList<>();
        list.add(new User("gan", "male"));
        list.add(new User("fwizhu", "female"));
        list.add(new User("kfc", "male"));
        ModelAndView modelAndView = new ModelAndView("example/list2");
        modelAndView.addObject("list", list);
        return modelAndView;
    }
    @GetMapping("/map")
    public ModelAndView map(){
        Map user = new HashMap<>();
        user.put("name", "姓名");
        user.put("sex", "male");
        ModelAndView modelAndView = new ModelAndView("example/map");
        modelAndView.addObject("map", user);
        return modelAndView;
    }
}
